package com.example.boot6rabbitmq2.consumer;


import com.rabbitmq.client.Channel;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.support.AmqpHeaders;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * 消费者
 */
@Component
public class MessageConsumer {

    //    可以配置消费者的一些信息，比如手动确认，最大的消费者数 ConsumeConfig
    @RabbitListener(queues = "chenfl.message",containerFactory = "qos_3")
    //@RabbitListener(queues = "chenfl.message")
    public void topicAccep (String message, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag){
        System.out.println("deliveryTag2=>"+deliveryTag);
        try {
            System.out.println("MessageConsumer2 topic received message : " +message);
            channel.basicAck(deliveryTag,false);
            System.out.println("---进行手动确认完成！---");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

}
